package com.nuanshui.heatedloan.configBehavior;


import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.nuanshui.framework.behavior.BehaviorAttribute;
import com.nuanshui.framework.behavior.IBehaviorInvoker;
import com.nuanshui.framework.lang.ClassUtil;
import com.nuanshui.framework.springContext.SpringContextUtil;

/**
 * Created by zxh on 2016/11/20.
 */
public class BehaviorUtil {

    public static <T> List<T> getBehaviors(String packageName)
    {

        Set<Class<?>> classFeatures = ClassUtil.getAnnotationClasses(BehaviorAttribute.class, packageName);

        List<T> list=new ArrayList<T>();
        for (Class<?> classItem:classFeatures) {
            T item=(T)SpringContextUtil.getBean(classItem);
            list.add(item);
        }
        return list;
    }

    public static void doInvoke(String packageName) {
        List<IBehaviorInvoker> list = getBehaviors(packageName);

        for (IBehaviorInvoker item : list) {
            item.doInvoke();
        }
    }

    public static void doInvoke(Class<?> cls) {
        doInvoke(cls.getPackage().getName());
    }
}
